﻿using Microsoft.AspNetCore.Mvc;
using PMS.Web.Factories.SystemModules;
using PMS.Web.Framework.Controllers;
using PMS.Web.Framework.Mvc.Filters;
using PMS.Web.Models.SystemModules;

namespace PMS.Web.Controllers.Backend.SystemManage
{
    public class SystemModuleManageController : BaseAdminController
    {
        #region Fields
        private readonly ISystemModuleModleFactory _systemModuleFactory;
        #endregion

        #region Ctor
        public SystemModuleManageController(ISystemModuleModleFactory systemModuleFactory)
        {
            _systemModuleFactory = systemModuleFactory;
        }
        #endregion

        #region Actions
        /// <summary>
        /// 系统模块管理列表页
        /// </summary>
        /// <param name="hashId"></param>
        /// <returns></returns>
        [ModulePermission]
        public virtual IActionResult SystemModuleListView(string hashId)
        {
            int moduleId = DecodeId(hashId);
            var model = _systemModuleFactory.GetSystemModuleModel(moduleId);
            
            ViewBag.PageTitle = model.DisplayName;
            ViewBag.BodyHtmlClass = "pear-container";
            return View(model);
        }

        /// <summary>
        /// 系统模块编辑页
        /// </summary>
        /// <param name="buttonId">按钮权限验证参数：点击按钮Id</param>
        /// <param name="moduleId">按钮权限验证参数：按钮所在系统模块Id</param>
        /// <param name="dataId">数据加载Id, 0则为新增数据</param>
        /// <returns></returns>
        [ButtonPermission]
        public virtual IActionResult SystemModuleEditView(int buttonId, int moduleId, int? dataId)
        {
            ViewBag.PageTitle = "系统菜单管理";
            SystemModuleModel model = _systemModuleFactory.PrepareSystemModuleModelForEdit(dataId.HasValue ? dataId.Value : 0);

            var buttonModels = _systemModuleFactory.PrepareAllModuleButtons();
            model.CustomProperties.Add("AllButtonModels", buttonModels);
            return View(model);
        }

        /// <summary>
        /// 后台系统菜单权限管理
        /// </summary>
        /// <returns></returns>
        [ModulePermission]
        public IActionResult SystemModuleAuthView(string hashId)
        {
            int moduleId = DecodeId(hashId);
            var model = _systemModuleFactory.GetSystemModuleModel(moduleId);

            ViewBag.PageTitle = model.DisplayName;
            return View(model);
        }
        #endregion
    }
}
